﻿using System;
using System.Collections.Generic;
using System.Web;
using UniversityManagementSystem.Manager;

namespace UniversityManagementSystem.DAL
{
    public class ClassSchedule:Course
    {
        public string BuildingName { get; set; }
        public string RoomNo { get; set; }
        public string ClassDay { get; set; }
        public TimeSpan ClassStarTime { get; set; }
        public TimeSpan ClassEndTime { get; set; }
        public string StartAmOrPm { get; set; }
        public string EndAmOrPm { get; set; }
        public string CourseName { get; set; }

        public string SaveSchedule(ClassSchedule aClassSchedule,string startTime,string endTime)
        {
            try
            {
                string startTimeHour = "";
                string timeStart = "";
                string[] startTimeTwentyFour = startTime.Split(':');
                string endTimeHour = "";
                string timeEnd = "";
                string[] endTimeTwentyFour = endTime.Split(':');
                if (aClassSchedule.StartAmOrPm == "PM")
                {
                    startTimeHour = (Convert.ToInt32(startTimeTwentyFour[0]) % 12 + 12).ToString();
                    timeStart = startTimeHour+":"+startTimeTwentyFour[1];
                    this.ClassStarTime = TimeSpan.Parse(timeStart);
                }
                else
                {
                    startTimeHour = (Convert.ToInt32(startTimeTwentyFour[0]) % 12).ToString();
                    aClassSchedule.ClassStarTime = TimeSpan.Parse(startTime);
                }
                if (aClassSchedule.EndAmOrPm == "PM")
                {
                    endTimeHour = (Convert.ToInt32(endTimeTwentyFour[0]) % 12 + 12).ToString();
                    timeEnd = endTimeHour + ":" + endTimeTwentyFour[1];
                    this.ClassEndTime = TimeSpan.Parse(timeEnd);
                }
                else
                {
                    endTimeHour = (Convert.ToInt32(endTimeTwentyFour[0]) % 12).ToString();
                    aClassSchedule.ClassEndTime = TimeSpan.Parse(endTime);
                }
                ClassScheduleManager manager = new ClassScheduleManager();
                return manager.SaveSchedule(aClassSchedule);
            }
            catch (Exception exception)
            {
                throw new Exception("Error Occured",exception);
            }
            
        }
    }
}